package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Slf4j
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
public class ShopController
{
    int num = 0;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 设置店铺营业状态
     * @param status
     * @return
     */
    @ApiOperation("设置店铺营业状态")
    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status)
    {
        log.info("营业状态为 = " + status);
        redisTemplate.opsForValue().set("SHOP_STATUS", status);
        return Result.success();
    }


    @PutMapping("/test/redis")
    public Result testRedis(@PathVariable Integer num)
    {
        log.info("写入数量为 = " + num);
        for (int i = 0; i < num; i++)
        {
            redisTemplate.opsForValue().set(num, "123456");
        }
        return Result.success();
    }


    /**
     * 查询店铺营业状态
     *
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("查询店铺营业状态")
    public Result<Integer> getStatus()
    {
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");
        log.info("获取店铺营业状态为 = " + shopStatus);
        return Result.success(shopStatus);
    }
}
